package com.gome.axwl.aoc.service.impl;

import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.anxl.sso.client.api.Account;
import com.anxl.sso.client.api.AccountInfo;
import com.gome.axwl.aoc.dao.AmAuditSettingDao;
import com.gome.axwl.aoc.entity.po.AmAuditSettingPo;
import com.gome.axwl.aoc.service.AuditSettingService;
import com.gome.axwl.aoc.service.feign.MasterDataFeignClient;
import com.gome.axwl.aoc.service.feign.PmsFeignClient;
import com.gome.commons.core.ResultData;
import com.gome.datasource.shard.annotation.ReadDatasource;

/**
 * @Description: 默认权限配置
 * @Auther: John Li
 * @Date: 2018/4/25 13:59
 */
@Service("auditSettingService")
public class AuditSettingServiceImpl implements AuditSettingService {

    private final static Logger log = LoggerFactory.getLogger(AuditSettingServiceImpl.class);

    @Autowired
    private AmAuditSettingDao amAuditSettingDao;

    @Autowired
    private PmsFeignClient pmsFeignClient;

    @Autowired
    private MasterDataFeignClient masterDataFeignClient;

    /**
     * 查询
     *
     * @param amAuditSettingPo
     * @return
     */
    @ReadDatasource
    @Override
    public List<AmAuditSettingPo> selectSelective(AmAuditSettingPo amAuditSettingPo) {
        return amAuditSettingDao.selectSelective(amAuditSettingPo);
    }

    /**
     * 新增默认审核配置
     *
     * @param amAuditSettingPo
     */
    @Override
    public void addAuditSetting(AmAuditSettingPo amAuditSettingPo) {
        amAuditSettingPo.setUserCode(UUID.randomUUID().toString());
        amAuditSettingDao.insert(amAuditSettingPo);
    }

    /**
     * 删除默认配置
     *
     * @param defaultId
     */
    @Override
    public ResultData deleteAuditSettingById(int defaultId) {
        int deleteStatus = amAuditSettingDao.deleteByPrimaryKey(defaultId);
        return ResultData.newResultData(deleteStatus);
    }

    /**
     * 更新默认配置
     *
     * @param amAuditSettingPo
     */
    @Override
    public Integer updateAuditSettingByDefaultId(AmAuditSettingPo amAuditSettingPo) {
        return amAuditSettingDao.updateByPrimaryKeySelective(amAuditSettingPo);
    }

    /**
     * 根据driverIds查询用户的登录设备信息集合
     *
     * @param accountNo
     * @return
     */
    @ReadDatasource
    @Override
    public AccountInfo getUserInfoByAccountNo(String accountNo) {
        return masterDataFeignClient.getUserByAccountNo(accountNo).getData();
    }

    /**
     * 分页查询设备信息
     *
     * @return
     */
    @ReadDatasource
    @Override
    public ResultData getAuditPrivilegeList(String keyword) {
        return pmsFeignClient.getAuditUserList(keyword,keyword,keyword);
    }

    @Override
    public Boolean isUserHasAuditPrivilege(String accountNo) {
        ResultData resultData = pmsFeignClient.isAuditUser(accountNo);
        return resultData.getData() != null;
    }

    @Override
    public List<Account> queryAccountByKeyword(String keyWord) {
        return masterDataFeignClient.queryAccountByKeyword(keyWord).getData();
    }

}
